package com.huaxin.hxcloud.activity;

import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;

import com.huaxin.common.BaseActivity;
import com.huaxin.common.view.MyFragmentTabHost;
import com.huaxin.hxcloud.R;
import com.huaxin.hxcloud.fragment.HxPunchCardFragment;
import com.huaxin.hxcloud.fragment.HxPunchStatisticsFragment;

import butterknife.BindView;

/**
 * @author songxf
 * @date 2017/11/23
 * @Desc 考勤打卡
 * Copyright HUAXIN DATA. All rights reserved.
 */
public class HxPunchCardActivity extends BaseActivity implements TabHost.OnTabChangeListener {

    @BindView(R.id.frame_content)
    FrameLayout       mFrameContent;
    @BindView(R.id.tabhost)
    MyFragmentTabHost mTabhost;
    private boolean initiated = false;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_punch_card;
    }

    @Override
    public void initView() {
        mTabhost.setup(this, getSupportFragmentManager(), R.id.frame_content);
        mTabhost.getTabWidget().setDividerDrawable(null);
        initTabs();
        mTabhost.setCurrentTab(0);
        mTabhost.setOnTabChangedListener(this);
    }

    private void initTabs() {
        TabHost.TabSpec tab = mTabhost.newTabSpec("打卡");
        View indicator = View.inflate(this, R.layout.tab_indicator, null);
        TextView title = (TextView) indicator.findViewById(R.id.tab_title);
        ImageView icon = (ImageView) indicator.findViewById(R.id.iv_icon);
        icon.setImageResource(R.drawable.tab_icon_punchcard);
        title.setText("打卡");
        tab.setIndicator(indicator);
        mTabhost.addTab(tab, HxPunchCardFragment.class, null);

        TabHost.TabSpec tab2 = mTabhost.newTabSpec("统计");
        View indicator2 = View.inflate(this, R.layout.tab_indicator, null);
        TextView title2 = (TextView) indicator2.findViewById(R.id.tab_title);
        ImageView icon2 = (ImageView) indicator2.findViewById(R.id.iv_icon);
        icon2.setImageResource(R.drawable.tab_icon_punchcard_statistics);
        title2.setText("统计");
        tab2.setIndicator(indicator2);
        mTabhost.addTab(tab2, HxPunchStatisticsFragment.class, null);
    }



    @Override
    public void onTabChanged(String s) {
        final int size = mTabhost.getTabWidget().getTabCount();
        for (int i = 0; i < size; i++) {
            View v = mTabhost.getTabWidget().getChildAt(i);
            if (i == mTabhost.getCurrentTab()) {
                v.setSelected(true);
            } else {
                v.setSelected(false);
            }
        }
    }
}
